#include "miscdata.h"
#include "symbol.h"
#include "creature.h"
#include "random.h"
#include "buffs.h"
#include "message.h"

BoxOfMatches::BoxOfMatches()
: _count( Random::Int( 4, 5, 0 ) )
{
}

bool BoxOfMatches::ItemType( uint* type ) const
{
    *type |= WIELDABLE_1H;
    return true;
}

bool BoxOfMatches::ItemWeight( uint* weight ) const
{
    *weight += 1;
    return true;
}

bool BoxOfMatches::Name( std::string* name, bool* plural, uint article ) const
{
    if ( _count > 0 ) {
        std::stringstream ss;
        ss << _count;
        if ( name->empty() && article == ARTICLE_INDEFINITE )
            *name += "a ";
        if ( article == ARTICLE_PLURAL )
            *name += "boxes of " + ss.str() + ( _count > 1 ? " matches each" : " match each" );
        else
            *name += "box of " + ss.str() + ( _count > 1 ? " matches" : " match" );
        return true;
    }
    if ( name->empty() && article == ARTICLE_INDEFINITE )
        *name += "an ";
    if ( article == ARTICLE_PLURAL )
        *name += "empty matchboxes";
    else
        *name += "empty matchbox";
    return true;
}

bool BoxOfMatches::Flammable( uint* flammableType ) const
{
    *flammableType |= FLAMMABLE_DESTROY | FLAMMABLE_BURN_EXTRA_SHORT | FLAMMABLE_BURN_BRIGHT;
    if ( _count > 0 )
        *flammableType |= FIRE_SOURCE_LIMITED;
    return true;
}

bool BoxOfMatches::ItemSymbol( IO::Sym* symbol ) const
{
    symbol->first = '=';
    return true;
}

bool BoxOfMatches::OnEaten( Creature* c )
{
    Bank().Manipulation( MANIPULATION_EAT_MATCHES, c, this );
    Destroy();
    return true;
}

bool BoxOfMatches::OnLight( Creature* c, Behaved* target )
{
    if ( _count > 0 )
        --_count;
    Bank().TernarySwitch( TERNARY_ALIGHT_FROM_MATCH, c, target, this );
    target->Call< BIOnSetFire >();
    return true;
}

bool Torch::ItemType( uint* type ) const
{
    *type |= WIELDABLE_1H;
    return true;
}

bool Torch::ItemWeight( uint* weight ) const
{
    *weight += 15;
    return true;
}

bool Torch::Name( std::string* name, bool* plural, uint article ) const
{
    if ( name->empty() && article == ARTICLE_INDEFINITE )
        *name += "a ";
    if ( article == ARTICLE_PLURAL )
        *name += "torches";
    else
        *name += "torch";
    return true;
}

bool Torch::Flammable( uint* flammableType ) const
{
    *flammableType |= FLAMMABLE_BURN_EXTRA_LONG | FLAMMABLE_SMOULDER_LONG | FLAMMABLE_CHAR | FLAMMABLE_BURN_BRIGHT;
    return true;
}

bool Torch::ItemSymbol( IO::Sym* symbol ) const
{
    symbol->first = '|';
    symbol->second = Colour( 192, 128, 64 );
    return true;
}

bool Torch::OnEaten( Creature* c )
{
    Bank().Manipulation( MANIPULATION_EAT_TORCH, c, this );
    Destroy();
    return true;
}